﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using weikebuluo.DAL;
using weikebuluo.Common;
using weikebuluo.Model;

namespace weikebuluo.web.admin.actives
{
    public partial class ggks : weikeweixin.web.admin.cs.adminbase
    {
        protected string ggks_url1 = "/web/wechat/guaguaka/styles/logo.png";
        protected string ggks_url2 = "/web/wechat/guaguaka/styles/footer.png";

        protected string ggks_time1 = DateTime.Now.ToString();
        protected string ggks_time2 = DateTime.Now.AddDays(6).ToString();

        h_ggks_dal ggksdal = new h_ggks_dal();
        h_ggks_model ggksmodel = new h_ggks_model();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"])) { 
                ggksmodel = ggksdal.GetModel(int.Parse(Request.QueryString["id"].ToString()));
                ggks_url1 = ggksmodel.ggks_url1;
                ggks_url2 = ggksmodel.ggks_url2;
                ggks_time1 = ggksmodel.ggks_time1.ToString();
                ggks_time2 = ggksmodel.ggks_time2.ToString();

            }

            switch (Request.Form["action"]) { 
                case "save":
                    save();
                    break;
            }

        }

        private void save() {
            if (!string.IsNullOrEmpty(Request.Form["id"])) {
                ggksmodel = ggksdal.GetModel(int.Parse(Request.Form["id"].ToString()));
            }
            string[] NTime = Request.Form["time"].Split('-');
            ggksmodel.ggks_time1 = DateTime.Parse(NTime[0].Trim());
            ggksmodel.ggks_time2 = DateTime.Parse(NTime[1].Trim());
            ggksmodel.ggks_url1 = Request.Form["icon"].Trim().ToString();
            ggksmodel.ggks_url2 = Request.Form["picurl"].Trim().ToString();
            ggksmodel.user_id = int.Parse(user_id);
            if (!string.IsNullOrEmpty(Request.Form["id"]))
            {
                ggksdal.Update(ggksmodel);
                Response.Write("{\"errno\":\"0\",\"tip\":\"修改成功,下一步！\",\"url\":\"gglset.aspx?id=" + Request.Form["id"] + "\",\"error\":\"\"}");
            }
            else {
                int id = ggksdal.Add(ggksmodel);
                Response.Write("{\"errno\":\"0\",\"tip\":\"设置成功，下一步！\",\"url\":\"gglset.aspx?id=" + id + "\",\"error\":\"\"}");
            }
            Response.End();
        }
    }
}